#pragma once
#include <nice2d/widgets/control.h>
#include <nice2d/widgets/draggablelabel.h>
#include <nice2d/widgets/boxlayout.h>

class TitleBarStyle : public LayoutStyle
{
    DECLARE_OBJECT(TitleBarStyle)
public:
    TitleBarStyle();
    virtual ~TitleBarStyle();
public:
    std::shared_ptr<LabelStyle> titleStyle;
    ControlStylePointer closeButtonStyle;
};

class TitleBar final : public HBoxLayout
{
    DECLARE_OBJECT(TitleBar);
    TitleBar();
public:
    static std::shared_ptr<TitleBar> create(const sf::String& title);
    ~TitleBar();
public:
    void setTitle(const sf::String& title);
    sf::String getTitle()const;

    void setDraggableTarget(ControlPointer target);
    boost::signals2::signal<void()> closeButtonPressed;

    boost::signals2::signal<void()> titleBarClicked;
protected:
    virtual void adjust()override;
    virtual void onStyleChanged()override;

    virtual void onMouseEnter() override;
    virtual void onMouseExit() override;
    virtual void onMousePressed(sf::Mouse::Button button) override;
    virtual void onMouseReleased(sf::Mouse::Button button) override;
private:
    std::unique_ptr<class TitleBarData> data;
};
